% clear; clc;
% load('data/recsys/netflix.mat');
% 
% para.tau = 1.01;
% [row, col, val] = find(data);
% 
% clear user item;
% 
% val = val - mean(val);
% val = val/std(val);
% 
% idx = randperm(length(val));
% 
% traIdx = idx(1:floor(length(val)*0.5));
% tstIdx = idx(ceil(length(val)*0.5): ceil(length(val)*0.75));
% 
% traData = sparse(row(traIdx), col(traIdx), val(traIdx), size(data,1), size(data,2));
% 
% clear idx data;
% 
% para.test.row  = row(tstIdx);
% para.test.col  = col(tstIdx);
% para.test.data = val(tstIdx);
% para.test.m = size(traData, 1);
% para.test.n = size(traData, 2);
% 
% clear traIdx tstIdx val row col;
% 
% %% start testing
% para.maxIter = 5000;
% para.decay = 0.95;
% para.tol = 10;
% 
% %% nuclear norm
% lambda = 112.5;
% 
% % ActiveSubspace
% method = 3;
% t = tic;
% [ ~, ~, ~, out{method,1} ] = mc_alt( traData', lambda, para );
% Time(method,1) = toc(t);
% RMSE(method,1) = out{method,1}.RMSE(end);
% 
% % FastMatComp
% t = tic;
% method = 4;
% para.maxR = 400;
% para.speedup = 1;
% para.regType = 1;
% para.exact = 0;
% % [~, ~, ~, out{method,1}] = AccSoftImpute( traData', lambda, para );
% [~, ~, ~, out{method,1}] = FastMatComp( traData', lambda, 1e+8, para );
% Time(method,1) = toc(t);
% RMSE(method,1) = out{method,1}.RMSE(end);
% 
% clear U S V t lambda;

% %% Fixed Rank
% para.tol = 200;
% estRank = 16;
% method = 1;
% t = tic;
% [~, ~, ~, out{method,2} ] = SoftImputeALS( traData', 1e-6, estRank, para );
% Time(method,2) = toc(t);
% RMSE(method,2) = out{method,2}.RMSE(end);

estRank = 100;
method = 2;
t = tic;
[~, ~, ~, out{method,2} ] = EOR1MP( traData', estRank, para );
Time(method,2) = toc(t);
RMSE(method,2) = out{method,2}.RMSE(end);

% non-convex
para.maxR = 20;
para.tol = 200;
for i = 3:5
    
para.decay = 0.925;   
para.regType = i - 2;

switch(para.regType)
    case 1
        lambda = 225;
        theta1 = lambda*2;
    case 2
        lambda = 60000;
        theta1 = sqrt(lambda);
    case 3
        lambda = 215;
        theta1 = 10;
end

% FAST
method = 2;

t = tic;
para.speedup = 1;
[~, ~, ~, out{method,i}] = FastMatComp( traData', lambda, theta1, para );
Time(method,i) = toc(t);
RMSE(method,i) = out{method,i}.RMSE(end);

clear U S V t method estRank;

end

clear U S V method t estRank;
clear i col row theta1 traData traIdx tstIdx user val data item para lambda;